package com.tancire.web.controller.platform.system;

import com.tancire.common.annotation.Log;
import com.tancire.common.core.controller.BaseController;
import com.tancire.common.core.domain.AjaxResult;
import com.tancire.common.core.page.TableDataInfo;
import com.tancire.common.enums.BusinessType;
import com.tancire.common.utils.poi.ExcelUtil;
import com.tancire.system.domain.SysAppLog;
import com.tancire.system.service.ISysAppLogService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 应用日志Controller
 *
 * @author tancire
 * @date 2024-06-13
 */
@RestController
@RequestMapping("/system/sysAppLog")
public class SysAppLogController extends BaseController {
    @Resource
    private ISysAppLogService sysAppLogService;

    /**
     * 查询应用日志列表
     */
    @PreAuthorize("@ss.hasPermi('system:sysAppLog:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysAppLog sysAppLog) {
        startPage();
        List<SysAppLog> list = sysAppLogService.selectSysAppLogList(sysAppLog);
        return getDataTable(list);
    }

    /**
     * 导出应用日志列表
     */
    @PreAuthorize("@ss.hasPermi('system:sysAppLog:export')")
    @Log(title = "应用日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysAppLog sysAppLog) {
        List<SysAppLog> list = sysAppLogService.selectSysAppLogList(sysAppLog);
        ExcelUtil<SysAppLog> util = new ExcelUtil<SysAppLog>(SysAppLog.class);
        util.exportExcel(response, list, "应用日志数据");
    }

    /**
     * 获取应用日志详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:sysAppLog:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(sysAppLogService.selectSysAppLogById(id));
    }


    /**
     * 删除应用日志
     */
    @PreAuthorize("@ss.hasPermi('system:sysAppLog:remove')")
    @Log(title = "应用日志", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(sysAppLogService.deleteSysAppLogByIds(ids));
    }
}
